<template>
  <div>
    <a-breadcrumb style="margin-bottom: 0.6rem;">
    <a-breadcrumb-item > <a href="../#/personal">主页</a></a-breadcrumb-item>
    <a-breadcrumb-item ><a href="../#/doctorRecruit/fractional/fractional">博士招生</a></a-breadcrumb-item>
    <a-breadcrumb-item ><a href="../#/doctorRecruit/fractional/fractional">博士分数线管理</a></a-breadcrumb-item>
    <a-breadcrumb-item style="color: rgba(0, 0, 0, 0.65);">博士分数线设置</a-breadcrumb-item>
  </a-breadcrumb>
    <a-alert class="card"  message="※博士分数线设置和按学科专业码设置同时设置时，以最后设置的分数线为准，外语分数线设置为单项匹配。不需要设置分数线的项目，分数线请设置为0" banner />

    <a-card>
      <a-breadcrumb>
    <a-breadcrumb-item > <a href="../#/doctorRecruit/fractional/professional">学士学位分数线设置</a></a-breadcrumb-item>
    <a-breadcrumb-item style="color: rgba(0, 0, 0, 0.65);">专业学位分数线设置</a-breadcrumb-item>
  </a-breadcrumb>
      <a-form :form="form">
        <a-row>
          <a-col :md="24" :sm="24">

            <a-col :md="12" :sm="24">
              <a-form-item
                label="领域"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-select v-decorator="['xkm',
                  {
                    rules: [{ message: '请选择领域' }],
                  }]"  @change="xkChange">
                  <a-select-option v-for="i in selectMenu.ly" :key="i.id" :value="i.xkdm">{{ i.xkdm+'-'+i.xkmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="专业"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
              <a-select v-decorator="['xkzym',
                  {
                    rules: [{ message: '请选择专业' }],
                  }]"  @change="zyChange">
                  <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.xkdm">{{ i.xkdm+'-'+i.xkmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="学科专业码"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input placeholder="请选择专业" disabled :value=xkdm />
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="招生年度"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-select v-decorator="['zsnj',
                  {
                    rules: [{ required: true, message: '招生年度' }],
                  }]" disabled>
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语听力"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wytlfsx',
                  {
                    rules: [{ required: true, message: '请输入外语听力!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语笔试"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wybsfsx',
                  {
                    rules: [{ required: true, message: '请输入外语笔试!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语口语"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wykyfsx',
                  {
                    rules: [{ required: true, message: '请输入外语口语!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语总分"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wyzffsx',
                  {
                    rules: [{ required: true, message: '请输入外语总分!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课一"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywkyfsx',
                  {
                    rules: [{  required: true,message: '请输入业务课一!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课二"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywkefsx',
                  {
                    rules: [{  message: '请输入业务课二!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课三"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywksfsx',
                  {
                    rules: [{ message: '请输入业务课三!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课总成绩"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywkzcjfsx',
                  {
                    rules: [{ required: true, message: '请输入业务课总成绩!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <div class="ant-pro-footer-toolbar">
      <a-button style="float: right;margin-top: 10px;" @click="handleSubmit" :loading="loadingBtn" type="primary">保存</a-button>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
const selectArr = ['TYPE0320', 'TYPE0321', 'TYPE0011', 'TYPE0360', 'TYPE0342', 'TYPE0018', 'TYPE0023', 'TYPE0126']

export default {
  data () {
    return {
      selectMenu: {
        ml:[],
        xk:[],
        ly:[]
      },
      loading: false,
      imageUrl: '',
      loadingBtn: false,
      queryParam:{
        'xk':'',
        'ml':'',
        'zy':''
      },
      xkdm:''
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  computed: {
   ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let code='04';
      let parms={xklb:code}
      let allRequest = [
        this.$api.base.subjectAll(parms)
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          ly: res[0].data
        }
      })
      this.$api.base.getSchoolYear().then(res=>{
        this.form.setFieldsValue({'zsnj':res.data.doctoralAdmissionYear})
      })
    },
     mlChange (code) {
        console.log(code)
        // this.queryParam.xk='';
        // this.queryParam.zy='';
        this.form.setFieldsValue({'xkm':'','xkzym':''})
        this.$set(this.selectMenu,'xk','')
        this.$set(this.selectMenu,'zy','')
        if(code){
          this.xkdm=code;
        var ml = this.selectMenu.ml
				this.$api.base.subjectAll({
					fjxkdm: code
				}).then(res => {
					if (res.data) {
						this.selectMenu = {
							ml: ml,
              xk: res.data,
              zy:[]
						}
					}
        })
        }
    },
    xkChange(code){
         this.form.setFieldsValue({'xkzym':''})
         this.$set(this.selectMenu,'zy','')
         if(code){
           this.xkdm=code;
        var ml = this.selectMenu.ml;
        var ly = this.selectMenu.ly;
				this.$api.base.linkageMajor({
					xkdm: code
				}).then(res => {
					if (res.data) {
						this.selectMenu = {
							ml: ml,
              ly: ly,
              zy:res.data
						}
					}
        })
         }
    },
    zyChange(code){
        if(code){
          this.xkdm=code;
        }
    },
    handleSearch () {
    },
    handleSubmit () {
      this.form.validateFields((err, values) => {
          if (err) {
            this.$message.error('请输入必填项')
            return
          }
      // console.log(this.form.getFieldsValue())
      this.$api.doctorRecruit.majorStuSave(this.form.getFieldsValue()).then(res => {
         this.$message.success(res.msg)
          this.form.setFieldsValue({'xkmlm':'','xkm':'','xkzym':'','wytlfsx':'','wybsfsx':'','wykyfsx':'','wyzffsx':'','ywkyfsx':'','ywkefsx':'','ywksfsx':'','ywkzcjfsx':''})
           this.xkdm=''
      	// this.$emit('success')
      }).finally(() => {
      	this.loadingBtn = false

      })

    })
    }

  }
}
</script>
